Ext.namespace("Microtraining.Admin.Company");
Mt = Microtraining.Admin;
Mt.Company={
	/**
	 * 全局配置
	 */
	Config:{
		/**
		 *分页:每页显示记录数
		 */
		PageSize:15,
		/**
		 *显示配置
		 */
		View:{
			/**
			 * 显示企业的视图相对企业列表Grid的位置
			 * 1:上方,2:下方,3:左侧,4:右侧,
			 */
			Direction:2,
			/**
			 *是否显示。
			 */
			IsShow:0,
			/**
			 * 是否固定显示企业信息页(或者打开新窗口)
			 */
			IsFix:0
		}
	},
	/**
	 * Cookie设置
	 */
	Cookie:new Ext.state.CookieProvider(),
	/**
	 * 初始化
	 */
	Init:function(){
		if (Mt.Company.Cookie.get('View.Direction')){
			Mt.Company.Config.View.Direction=Mt.Company.Cookie.get('View.Direction');
		}
		if (Mt.Company.Cookie.get('View.IsFix')!=null){
			Mt.Company.Config.View.IsFix=Mt.Company.Cookie.get('View.IsFix');
		}
	}
};
/**
 * Model:数据模型
 */
Mt.Company.Store = {
	/**
	 * 企业
	 */
	companyStore:new Ext.data.Store({
		reader: new Ext.data.JsonReader({
			totalProperty: 'totalCount',
			successProperty: 'success',
			root: 'data',remoteSort: true,
			fields : [
		        {name: 'company_id',type: 'int'},
		        {name: 'company_name',type: 'string'},
		        {name: 'logo_image',type: 'string'},
		        {name: 'address',type: 'string'},
		        {name: 'tel',type: 'string'},
		        {name: 'links_img',type: 'string'},
		        {name: 'links_url',type: 'string'},
		        {name: 'begin_time',type: 'date',dateFormat:'Y-m-d H:i:s'},
		        {name: 'end_time',type: 'date',dateFormat:'Y-m-d H:i:s'}
			]}
		),
		writer: new Ext.data.JsonWriter({
			encode: false
		}),
		listeners : {
			beforeload : function(store, options) {
				if (Ext.isReady) {
					if (!options.params.limit)options.params.limit=Mt.Company.Config.PageSize;
					Ext.apply(options.params, Mt.Company.View.Running.companyGrid.filter);//保证分页也将查询条件带上
				}
			}
		}
	}),
  /**
   * 地区
   */
  areaStore:new Ext.data.Store({
    reader: new Ext.data.JsonReader({
      totalProperty: 'totalCount',
      successProperty: 'success',
      root: 'data',remoteSort: true,
      fields : [
        {name: 'area_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'area_name',type: 'string'}
      ]}
    ),
    writer: new Ext.data.JsonWriter({
      encode: false 
    }),
    listeners : {
      beforeload : function(store, options) {
        if (Ext.isReady) {
          if (!options.params.limit)options.params.limit=Mt.Company.Config.PageSize;
          Ext.apply(options.params, Mt.Company.View.Running.areaGrid.filter);//保证分页也将查询条件带上
        }
      }
    }
  }),
  /**
   * 部门
   */
  departmentStore:new Ext.data.Store({
    reader: new Ext.data.JsonReader({
      totalProperty: 'totalCount',
      successProperty: 'success',
      root: 'data',remoteSort: true,
      fields : [
        {name: 'department_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'department_name',type: 'string'}
      ]}
    ),
    writer: new Ext.data.JsonWriter({
      encode: false 
    }),
    listeners : {
      beforeload : function(store, options) {
        if (Ext.isReady) {
          if (!options.params.limit)options.params.limit=Mt.Company.Config.PageSize;
          Ext.apply(options.params, Mt.Company.View.Running.departmentGrid.filter);//保证分页也将查询条件带上
        }
      }
    }
  }),
  /**
   * 职位
   */
  positionStore:new Ext.data.Store({
    reader: new Ext.data.JsonReader({
      totalProperty: 'totalCount',
      successProperty: 'success',
      root: 'data',remoteSort: true,
      fields : [
        {name: 'position_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'department_name',type: 'string'},
        {name: 'position_name',type: 'string'}
      ]}
    ),
    writer: new Ext.data.JsonWriter({
      encode: false 
    }),
    listeners : {
      beforeload : function(store, options) {
        if (Ext.isReady) {
          if (!options.params.limit)options.params.limit=Mt.Company.Config.PageSize;
          Ext.apply(options.params, Mt.Company.View.Running.positionGrid.filter);//保证分页也将查询条件带上
        }
      }
    }
  }),
  /**
   * 部门
   */
  departmentStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/department.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'departments',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'department_id'
    }, [
      {name: 'department_id', mapping: 'department_id'},
      {name: 'department_name', mapping: 'department_name'}
    ])
  }),
  /**
   * 企业课程
   */
  lessonStore:new Ext.data.Store({
    reader: new Ext.data.JsonReader({
      totalProperty: 'totalCount',
      successProperty: 'success',
      root: 'data',remoteSort: true,
      fields : [
        {name: 'lesson_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'lesson_name',type: 'string'},
        {name: 'keywords',type: 'string'},
        {name: 'begin_time',type: 'date',dateFormat:'Y-m-d H:i:s'},
        {name: 'end_time',type: 'date',dateFormat:'Y-m-d H:i:s'},
        {name: 'sort_order',type: 'int'}
      ]}
    ),
    writer: new Ext.data.JsonWriter({
      encode: false 
    }),
    listeners : {
      beforeload : function(store, options) {
        if (Ext.isReady) {
          if (!options.params.limit)options.params.limit=Mt.Company.Config.PageSize;
          Ext.apply(options.params, Mt.Company.View.Running.lessonGrid.filter);//保证分页也将查询条件带上
        }
      }
    }
  })
};
/**
 * View:企业显示组件
 */
Mt.Company.View={
	/**
	 * 编辑窗口：新建或者修改企业
	 */
	EditWindow:Ext.extend(Ext.Window,{
		constructor : function(config) {
			config = Ext.apply({
				/**
				 * 自定义类型:保存类型
				 * 0:保存窗口,1:修改窗口
				 */
				savetype:0,
				closeAction : "hide",
				constrainHeader:true,maximizable: true,collapsible: true,
				width : 450,height : 550,minWidth : 400,minHeight : 450,
				layout : 'fit',plain : true,buttonAlign : 'center',
				defaults : {
					autoScroll : true
				},
				listeners:{
					beforehide:function(){
						this.editForm.form.getEl().dom.reset();
					}
				},
				items : [
					new Ext.form.FormPanel({
						ref:'editForm',layout:'form',fileUpload: true,
						labelWidth : 100,labelAlign : "center",
						bodyStyle : 'padding:5px 5px 0',align : "center",
						api : {},
						defaults : {
							xtype : 'textfield',anchor:'98%'
						},
						items : [
              {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
              {fieldLabel : '企业名称',name : 'company_name',allowBlank:false},
              {xtype: 'hidden',  name : 'logo_image',ref:'../logo_image'},
              {xtype: 'hidden',  name : 'links_img',ref:'../links_img'},
              {fieldLabel : 'logo图片',name : 'logo_imageUpload',ref:'../logo_imageUpload',xtype:'fileuploadfield',allowBlank:false,
                emptyText: '请上传logo图片文件',buttonText: '',accept:'image/*',buttonCfg: {iconCls: 'upload-icon'}},
              {fieldLabel : '地址',name : 'address',allowBlank:false},
              {fieldLabel : '电话',name : 'tel',allowBlank:false},
              {fieldLabel : '广告图片',name : 'links_imgUpload',ref:'../links_imgUpload',xtype:'fileuploadfield',
                emptyText: '请上传logo图片文件',buttonText: '',accept:'image/*',buttonCfg: {iconCls: 'upload-icon'}},
              {fieldLabel : '地址',name : 'links_url'},
              {fieldLabel : '开始时间',name : 'begin_time',xtype : 'datefield',format : "Y-m-d",allowBlank:false,ref:'begin_time'},
              {fieldLabel : '结束时间',name : 'end_time',xtype : 'datefield',format : "Y-m-d",allowBlank:false,ref:'end_time'}
						]
					})
				],
				buttons : [{
					text: "",ref : "../saveBtn",scope:this,
					handler : function() {
						if (!this.editForm.getForm().isValid()) {
							return;
						}
            if(this.editForm.begin_time.getValue() >= this.editForm.end_time.getValue()){
              Ext.Msg.alert("提示","结束时间不能小于开始时间！");
              return;
            }
						editWindow=this;
						if (this.savetype==0){
							this.editForm.api.submit=ExtServiceCompany.save;
							this.editForm.getForm().submit({
								success : function(form, action) {
									Ext.Msg.alert("提示", "保存成功！");
									Mt.Company.View.Running.companyGrid.doSelectCompany();
									form.reset();
									editWindow.hide();
								},
								failure : function(form, response) {
									Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
								}
							});
						}else{
							this.editForm.api.submit=ExtServiceCompany.update;
							this.editForm.getForm().submit({
								success : function(form, action) {
									Mt.Company.View.Running.companyGrid.store.reload();
									Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
										Mt.Company.View.Running.companyGrid.bottomToolbar.doRefresh();
									}});
									form.reset();
									editWindow.hide();
								},
								failure : function(form, response) {
									Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
								}
							});
						}
					}
				}, {
					text : "取 消",scope:this,
					handler : function() {
						this.hide();
					}
				}, {
					text : "重 置",ref:'../resetBtn',scope:this,
					handler : function() {
						this.editForm.form.loadRecord(Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected());
            			this.logo_imageUpload.setValue(this.logo_image.getValue());
            			this.links_imgUpload.setValue(this.links_img.getValue());
					}
				}]
			}, config);
			Mt.Company.View.EditWindow.superclass.constructor.call(this, config);
		}
	}),
	/**
	 * 显示企业详情
	 */
	CompanyView:{
		/**
		 * Tab页：容器包含显示与企业所有相关的信息
		 */
		Tabs:Ext.extend(Ext.TabPanel,{
			constructor : function(config) {
				config = Ext.apply({
					region : 'south',collapseMode : 'mini',split : true,
					activeTab: 1, tabPosition:"bottom",resizeTabs : true,
					header:false,enableTabScroll : true,tabWidth:'auto', margins : '0 3 3 0',
					defaults : {
						autoScroll : true,
						layout:'fit'
					},
					listeners:{
						beforetabchange:function(tabs,newtab,currentTab){
							if (tabs.tabFix==newtab){
								if (Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected()==null){
									Ext.Msg.alert('提示', '请先选择企业！');
									return false;
								}
								Mt.Company.Config.View.IsShow=1;
								Mt.Company.View.Running.companyGrid.showCompany();
								Mt.Company.View.Running.companyGrid.tvpView.menu.mBind.setChecked(false);
								return false;
							}
						}
					},
					items: [
						{title:'+',tabTip:'取消固定',ref:'tabFix',iconCls:'icon-fix'}
					]
				}, config);
				Mt.Company.View.CompanyView.Tabs.superclass.constructor.call(this, config);
        Mt.Company.View.Running.areaGrid=new Mt.Company.View.AreaView.Grid();
        Mt.Company.View.Running.departmentGrid=new Mt.Company.View.DepartmentView.Grid();
        Mt.Company.View.Running.positionGrid=new Mt.Company.View.PositionView.Grid();
        Mt.Company.View.Running.lessonGrid=new Mt.Company.View.LessonView.Grid();
				this.onAddItems();
			},
			/**
			 * 根据布局调整Tabs的宽度或者高度以及折叠
			 */
			enableCollapse:function(){
				if ((Mt.Company.Config.View.Direction==1)||(Mt.Company.Config.View.Direction==2)){
					this.width =Ext.getBody().getViewSize().width;
					this.height=Ext.getBody().getViewSize().height/2;
				}else{
					this.width =Ext.getBody().getViewSize().width/2;
					this.height=Ext.getBody().getViewSize().height;
				}
				this.ownerCt.setSize(this.width,this.height);
				if (this.ownerCt.collapsed)this.ownerCt.expand();
				this.ownerCt.collapsed=false;
			},
			onAddItems:function(){
				this.add(
					{title: '基本信息',ref:'tabCompanyDetail',iconCls:'tabs',
					 tpl: [
						 '<table class="viewdoblock">',
             '  <tr class="entry"><td class="head">企业名称</td><td class="content">{company_name}</td></tr>',
             '  <tr class="entry"><td class="head">logo图片路径</td><td class="content">{logo_image}</td></tr>',
             '  <tr class="entry"><td class="head">logo图片</td><td class="content"><tpl if="logo_image"><a href="upload/images/{logo_image}" target="_blank"><img src="upload/images/{logo_image}" /></a></tpl></td></tr>',
             '  <tr class="entry"><td class="head">地址</td><td class="content">{address}</td></tr>',
             '  <tr class="entry"><td class="head">电话</td><td class="content">{tel}</td></tr>',
             '  <tr class="entry"><td class="head">广告图片路径</td><td class="content">{links_img}</td></tr>',
             '  <tr class="entry"><td class="head">广告图片</td><td class="content"><tpl if="links_img"><a href="upload/images/{links_img}" target="_blank"><img src="upload/images/{links_img}" /></a></tpl></td></tr>',
             '  <tr class="entry"><td class="head">广告链接地址</td><td class="content">{links_url}</td></tr>',
             '  <tr class="entry"><td class="head">开始时间</td><td class="content">{begin_time:date("Y-m-d")}</td></tr>',
             '  <tr class="entry"><td class="head">结束时间</td><td class="content">{end_time:date("Y-m-d")}</td></tr>',
						 '</table>'
					 ]}
				);
        this.add(
          {title: '地区',iconCls:'tabs',tabWidth:150,
           items:[Mt.Company.View.Running.areaGrid]
          },
          {title: '部门',iconCls:'tabs',tabWidth:150,
           items:[Mt.Company.View.Running.departmentGrid]
          },
          {title: '职位',iconCls:'tabs',tabWidth:150,
           items:[Mt.Company.View.Running.positionGrid]
          },
          {title: '企业课程',iconCls:'tabs',tabWidth:150,
           items:[Mt.Company.View.Running.lessonGrid]
          }
        );
			}
		}),
		/**
		 * 窗口:显示企业信息
		 */
		Window:Ext.extend(Ext.Window,{
			constructor : function(config) {
				config = Ext.apply({
					title:"查看企业",constrainHeader:true,maximizable: true,minimizable : true,
					width : 705,height : 500,minWidth : 450,minHeight : 400,
					layout : 'fit',resizable:true,plain : true,bodyStyle : 'padding:5px;',
					closeAction : "hide",
					items:[new Mt.Company.View.CompanyView.Tabs({ref:'winTabs',tabPosition:'top'})],
					listeners: {
						minimize:function(w){
							w.hide();
							Mt.Company.Config.View.IsShow=0;
							Mt.Company.View.Running.companyGrid.tvpView.menu.mBind.setChecked(true);
						},
						hide:function(w){
							Mt.Company.View.Running.companyGrid.tvpView.toggle(false);
						}
					}/*,
					buttons: [{
						text: '新增企业',scope:this,
						handler : function() {this.hide();Mt.Company.View.Running.companyGrid.addCompany();}
					},{
						text: '修改企业',scope:this,
						handler : function() {this.hide();Mt.Company.View.Running.companyGrid.updateCompany();}
					}]*/
				}, config);
				Mt.Company.View.CompanyView.Window.superclass.constructor.call(this, config);
			}
		})
	},
	/**
	 * 视图：地区列表
	 */
	AreaView:{
		/**
		 *  当前创建的地区编辑窗口
		 */
		edit_window:null,
		/**
		 * 编辑窗口：新建或者修改地区
		 */
		EditWindow:Ext.extend(Ext.Window,{
			constructor : function(config) {
				config = Ext.apply({
					/**
					 * 自定义类型:保存类型
					 * 0:保存窗口,1:修改窗口
					 */
					savetype:0,closeAction : "hide",constrainHeader:true,maximizable: true,collapsible: true,
					width : 450,height : 550,minWidth : 400,minHeight : 450,
					layout : 'fit',plain : true,buttonAlign : 'center',
					defaults : {autoScroll : true},
					listeners:{
						beforehide:function(){
							this.editForm.form.getEl().dom.reset();
						}
					},
					items : [
						new Ext.form.FormPanel({
							ref:'editForm',layout:'form',
							labelWidth : 100,labelAlign : "center",
							bodyStyle : 'padding:5px 5px 0',align : "center",
							api : {},
							defaults : {
								xtype : 'textfield',anchor:'98%'
							},
							items : [
                {xtype: 'hidden',name : 'area_id',ref:'../area_id'},
                {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
                {fieldLabel : '地区名称',name : 'area_name'}
							]
						})
					],
					buttons : [{
						text: "",ref : "../saveBtn",scope:this,
						handler : function() {

							if (!this.editForm.getForm().isValid()) {
								return;
							}
							editWindow=this;
							if (this.savetype==0){
								this.editForm.api.submit=ExtServiceArea.save;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.alert("提示", "保存成功！");
										Mt.Company.View.Running.areaGrid.doSelectArea();
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}else{
								this.editForm.api.submit=ExtServiceArea.update;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
											Mt.Company.View.Running.areaGrid.bottomToolbar.doRefresh();
										}});
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}
						}
					}, {
						text : "取 消",scope:this,
						handler : function() {
							this.hide();
						}
					}, {
						text : "重 置",ref:'../resetBtn',scope:this,
						handler : function() {
							this.editForm.form.loadRecord(Mt.Company.View.Running.areaGrid.getSelectionModel().getSelected());

						}
					}]
				}, config);
				Mt.Company.View.AreaView.EditWindow.superclass.constructor.call(this, config);
			}
		}),
		/**
		 * 查询条件
		 */
		filter:null,
		/**
		 * 视图：地区列表
		 */
		Grid:Ext.extend(Ext.grid.GridPanel, {
			constructor : function(config) {
				config = Ext.apply({
					store : Mt.Company.Store.areaStore,sm : this.sm,
					frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
					loadMask : true,stripeRows : true,headerAsText : false,
					defaults : {autoScroll : true},
					cm : new Ext.grid.ColumnModel({
						defaults:{
							width:120,sortable : true
						},
						columns : [
              this.sm,
              {header : '标识',dataIndex : 'area_id',hidden:true},
              {header : '地区名称',dataIndex : 'area_name'}
						]
					}),
					tbar : {
						xtype : 'container',layout : 'anchor',
						height : 27,style:'font-size:14px',
						defaults : {
							height : 27,anchor : '100%'
						},
						items : [
							/*new Ext.Toolbar({
								defaults:{
								  scope: this
								},
								items : [
									{
										text: '反选',iconCls : 'icon-reverse',
										handler: function(){
											this.onReverseSelect();
										}
									},'-',{
										text : '添加地区',iconCls : 'icon-add',
										handler : function() {
											this.addArea();
										}
									},'-',{
										text : '修改地区',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
										handler : function() {
											this.updateArea();
										}
									},'-',{
										text : '删除地区', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
										handler : function() {
											this.deleteArea();
										}
									},'-']}
						)*/]
					},
					bbar: new Ext.PagingToolbar({
						pageSize: Mt.Company.Config.PageSize,
						store: Mt.Company.Store.areaStore,scope:this,autoShow:true,displayInfo: true,
						displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',emptyMsg: "无显示数据",
						items: [
							{xtype:'label', text: '每页显示'},
							{xtype:'numberfield', value:Mt.Company.Config.PageSize,minValue:1,width:35,style:'text-align:center',allowBlank: false,
								listeners:
								{
									change:function(Field, newValue, oldValue){
										var num = parseInt(newValue);
										if (isNaN(num) || !num || num<1)
										{
											num = Mt.Company.Config.PageSize;
											Field.setValue(num);
										}
										this.ownerCt.pageSize= num;
										Mt.Company.Config.PageSize = num;
										this.ownerCt.ownerCt.doSelectArea();
									},
									specialKey :function(field,e){
										if (e.getKey() == Ext.EventObject.ENTER){
											var num = parseInt(field.getValue());
											if (isNaN(num) || !num || num<1)num = Mt.Company.Config.PageSize;
											this.ownerCt.pageSize= num;
											Mt.Company.Config.PageSize = num;
											this.ownerCt.ownerCt.doSelectArea();
										}
									}
								}
							},{xtype:'label', text: '个'}
						]
					})
				}, config);
				/**
				 * 地区数据模型获取数据Direct调用
				 */
				Mt.Company.Store.areaStore.proxy=new Ext.data.DirectProxy({
					api: {read:ExtServiceArea.queryPageArea}
				});
				Mt.Company.View.AreaView.Grid.superclass.constructor.call(this, config);
			},
			/**
			 * 行选择器
			 */
			sm : new Ext.grid.CheckboxSelectionModel({
				listeners : {
					selectionchange:function(sm) {
						// 判断删除和更新按钮是否可以激活
						this.grid.btnRemove.setDisabled(sm.getCount() < 1);
						this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
					}
				}
			}),
			/**
			 * 查询符合条件的地区
			 */
			doSelectArea : function() {
				if (Mt.Company.View.Running.companyGrid&&Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected()){
					var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
					var condition = {'company_id':company_id,'start':0,'limit':Mt.Company.Config.PageSize};
					this.filter     ={'company_id':company_id};
					ExtServiceArea.queryPageArea(condition,function(provider, response) {
						if (response.result){
							if (response.result.data) {
								var result       = new Array();
								result['data']     =response.result.data;
								result['totalCount'] =response.result.totalCount;
								Mt.Company.Store.areaStore.loadData(result);
							} else {
								Mt.Company.Store.areaStore.removeAll();
								Ext.Msg.alert('提示', '无符合条件的地区！');
							}

							if (Mt.Company.Store.areaStore.getTotalCount()>Mt.Company.Config.PageSize){
								 Mt.Company.View.Running.areaGrid.bottomToolbar.show();
							}else{
								 Mt.Company.View.Running.areaGrid.bottomToolbar.hide();
							}
							Mt.Company.View.Running.companyGrid.ownerCt.doLayout();
						}
					});
				}
			},
			/**
			 * 反选
			 */
			onReverseSelect:function() {
				for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
					if (this.sm.isSelected(i)) {
						this.sm.deselectRow(i);
					}else {
						this.sm.selectRow(i, true);
					}
				}
			},
			/**
			 * 新建地区
			 */
			addArea : function(){
				if (Mt.Company.View.AreaView.edit_window==null){
					Mt.Company.View.AreaView.edit_window=new Mt.Company.View.AreaView.EditWindow();
				}
				Mt.Company.View.AreaView.edit_window.resetBtn.setVisible(false);
				Mt.Company.View.AreaView.edit_window.saveBtn.setText('保 存');
				Mt.Company.View.AreaView.edit_window.setTitle('添加地区');
				Mt.Company.View.AreaView.edit_window.savetype=0;
				Mt.Company.View.AreaView.edit_window.area_id.setValue("");
				var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
				Mt.Company.View.AreaView.edit_window.company_id.setValue(company_id);

				Mt.Company.View.AreaView.edit_window.show();
				Mt.Company.View.AreaView.edit_window.maximize();
			},
			/**
			 * 编辑地区时先获得选中的地区信息
			 */
			updateArea : function() {
				if (Mt.Company.View.AreaView.edit_window==null){
					Mt.Company.View.AreaView.edit_window=new Mt.Company.View.AreaView.EditWindow();
				}
				Mt.Company.View.AreaView.edit_window.saveBtn.setText('修 改');
				Mt.Company.View.AreaView.edit_window.resetBtn.setVisible(true);
				Mt.Company.View.AreaView.edit_window.setTitle('修改地区');
				Mt.Company.View.AreaView.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
				Mt.Company.View.AreaView.edit_window.savetype=1;

				Mt.Company.View.AreaView.edit_window.show();
				Mt.Company.View.AreaView.edit_window.maximize();
			},
			/**
			 * 删除地区
			 */
			deleteArea : function() {
				Ext.Msg.confirm('提示', '确实要删除所选的地区吗?', this.confirmDeleteArea,this);
			},
			/**
			 * 确认删除地区
			 */
			confirmDeleteArea : function(btn) {
				if (btn == 'yes') {
					var del_area_ids ="";
					var selectedRows  = this.getSelectionModel().getSelections();
					for ( var flag = 0; flag < selectedRows.length; flag++) {
						del_area_ids=del_area_ids+selectedRows[flag].data.area_id+",";
					}
					ExtServiceArea.deleteByIds(del_area_ids);
					this.doSelectArea();
					Ext.Msg.alert("提示", "删除成功！");
				}
			}
		})
	},
	/**
	 * 视图：部门列表
	 */
	DepartmentView:{
		/**
		 *  当前创建的部门编辑窗口
		 */
		edit_window:null,
		/**
		 * 编辑窗口：新建或者修改部门
		 */
		EditWindow:Ext.extend(Ext.Window,{
			constructor : function(config) {
				config = Ext.apply({
					/**
					 * 自定义类型:保存类型
					 * 0:保存窗口,1:修改窗口
					 */
					savetype:0,closeAction : "hide",constrainHeader:true,maximizable: true,collapsible: true,
					width : 450,height : 550,minWidth : 400,minHeight : 450,
					layout : 'fit',plain : true,buttonAlign : 'center',
					defaults : {autoScroll : true},
					listeners:{
						beforehide:function(){
							this.editForm.form.getEl().dom.reset();
						}
					},
					items : [
						new Ext.form.FormPanel({
							ref:'editForm',layout:'form',
							labelWidth : 100,labelAlign : "center",
							bodyStyle : 'padding:5px 5px 0',align : "center",
							api : {},
							defaults : {
								xtype : 'textfield',anchor:'98%'
							},
							items : [
                {xtype: 'hidden',name : 'department_id',ref:'../department_id'},
                {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
                {fieldLabel : '部门名称',name : 'department_name'}
							]
						})
					],
					buttons : [{
						text: "",ref : "../saveBtn",scope:this,
						handler : function() {

							if (!this.editForm.getForm().isValid()) {
								return;
							}
							editWindow=this;
							if (this.savetype==0){
								this.editForm.api.submit=ExtServiceDepartment.save;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.alert("提示", "保存成功！");
										Mt.Company.View.Running.departmentGrid.doSelectDepartment();
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}else{
								this.editForm.api.submit=ExtServiceDepartment.update;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
											Mt.Company.View.Running.departmentGrid.bottomToolbar.doRefresh();
										}});
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}
						}
					}, {
						text : "取 消",scope:this,
						handler : function() {
							this.hide();
						}
					}, {
						text : "重 置",ref:'../resetBtn',scope:this,
						handler : function() {
							this.editForm.form.loadRecord(Mt.Company.View.Running.departmentGrid.getSelectionModel().getSelected());

						}
					}]
				}, config);
				Mt.Company.View.DepartmentView.EditWindow.superclass.constructor.call(this, config);
			}
		}),
		/**
		 * 查询条件
		 */
		filter:null,
		/**
		 * 视图：部门列表
		 */
		Grid:Ext.extend(Ext.grid.GridPanel, {
			constructor : function(config) {
				config = Ext.apply({
					store : Mt.Company.Store.departmentStore,sm : this.sm,
					frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
					loadMask : true,stripeRows : true,headerAsText : false,
					defaults : {autoScroll : true},
					cm : new Ext.grid.ColumnModel({
						defaults:{
							width:120,sortable : true
						},
						columns : [
              this.sm,
              {header : '标识',dataIndex : 'department_id',hidden:true},
              {header : '部门名称',dataIndex : 'department_name'}
						]
					}),
					tbar : {
						xtype : 'container',layout : 'anchor',
						height : 27,style:'font-size:14px',
						defaults : {
							height : 27,anchor : '100%'
						},
						items : [
							/*new Ext.Toolbar({
								defaults:{
								  scope: this
								},
								items : [
									{
										text: '反选',iconCls : 'icon-reverse',
										handler: function(){
											this.onReverseSelect();
										}
									},'-',{
										text : '添加部门',iconCls : 'icon-add',
										handler : function() {
											this.addDepartment();
										}
									},'-',{
										text : '修改部门',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
										handler : function() {
											this.updateDepartment();
										}
									},'-',{
										text : '删除部门', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
										handler : function() {
											this.deleteDepartment();
										}
									},'-']}
						)*/]
					},
					bbar: new Ext.PagingToolbar({
						pageSize: Mt.Company.Config.PageSize,
						store: Mt.Company.Store.departmentStore,scope:this,autoShow:true,displayInfo: true,
						displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',emptyMsg: "无显示数据",
						items: [
							{xtype:'label', text: '每页显示'},
							{xtype:'numberfield', value:Mt.Company.Config.PageSize,minValue:1,width:35,style:'text-align:center',allowBlank: false,
								listeners:
								{
									change:function(Field, newValue, oldValue){
										var num = parseInt(newValue);
										if (isNaN(num) || !num || num<1)
										{
											num = Mt.Company.Config.PageSize;
											Field.setValue(num);
										}
										this.ownerCt.pageSize= num;
										Mt.Company.Config.PageSize = num;
										this.ownerCt.ownerCt.doSelectDepartment();
									},
									specialKey :function(field,e){
										if (e.getKey() == Ext.EventObject.ENTER){
											var num = parseInt(field.getValue());
											if (isNaN(num) || !num || num<1)num = Mt.Company.Config.PageSize;
											this.ownerCt.pageSize= num;
											Mt.Company.Config.PageSize = num;
											this.ownerCt.ownerCt.doSelectDepartment();
										}
									}
								}
							},{xtype:'label', text: '个'}
						]
					})
				}, config);
				/**
				 * 部门数据模型获取数据Direct调用
				 */
				Mt.Company.Store.departmentStore.proxy=new Ext.data.DirectProxy({
					api: {read:ExtServiceDepartment.queryPageDepartment}
				});
				Mt.Company.View.DepartmentView.Grid.superclass.constructor.call(this, config);
			},
			/**
			 * 行选择器
			 */
			sm : new Ext.grid.CheckboxSelectionModel({
				listeners : {
					selectionchange:function(sm) {
						// 判断删除和更新按钮是否可以激活
						this.grid.btnRemove.setDisabled(sm.getCount() < 1);
						this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
					}
				}
			}),
			/**
			 * 查询符合条件的部门
			 */
			doSelectDepartment : function() {
				if (Mt.Company.View.Running.companyGrid&&Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected()){
					var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
					var condition = {'company_id':company_id,'start':0,'limit':Mt.Company.Config.PageSize};
					this.filter     ={'company_id':company_id};
					ExtServiceDepartment.queryPageDepartment(condition,function(provider, response) {
						if (response.result){
							if (response.result.data) {
								var result       = new Array();
								result['data']     =response.result.data;
								result['totalCount'] =response.result.totalCount;
								Mt.Company.Store.departmentStore.loadData(result);
							} else {
								Mt.Company.Store.departmentStore.removeAll();
								Ext.Msg.alert('提示', '无符合条件的部门！');
							}

							if (Mt.Company.Store.departmentStore.getTotalCount()>Mt.Company.Config.PageSize){
								 Mt.Company.View.Running.departmentGrid.bottomToolbar.show();
							}else{
								 Mt.Company.View.Running.departmentGrid.bottomToolbar.hide();
							}
							Mt.Company.View.Running.companyGrid.ownerCt.doLayout();
						}
					});
				}
			},
			/**
			 * 反选
			 */
			onReverseSelect:function() {
				for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
					if (this.sm.isSelected(i)) {
						this.sm.deselectRow(i);
					}else {
						this.sm.selectRow(i, true);
					}
				}
			},
			/**
			 * 新建部门
			 */
			addDepartment : function(){
				if (Mt.Company.View.DepartmentView.edit_window==null){
					Mt.Company.View.DepartmentView.edit_window=new Mt.Company.View.DepartmentView.EditWindow();
				}
				Mt.Company.View.DepartmentView.edit_window.resetBtn.setVisible(false);
				Mt.Company.View.DepartmentView.edit_window.saveBtn.setText('保 存');
				Mt.Company.View.DepartmentView.edit_window.setTitle('添加部门');
				Mt.Company.View.DepartmentView.edit_window.savetype=0;
				Mt.Company.View.DepartmentView.edit_window.department_id.setValue("");
				var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
				Mt.Company.View.DepartmentView.edit_window.company_id.setValue(company_id);

				Mt.Company.View.DepartmentView.edit_window.show();
				Mt.Company.View.DepartmentView.edit_window.maximize();
			},
			/**
			 * 编辑部门时先获得选中的部门信息
			 */
			updateDepartment : function() {
				if (Mt.Company.View.DepartmentView.edit_window==null){
					Mt.Company.View.DepartmentView.edit_window=new Mt.Company.View.DepartmentView.EditWindow();
				}
				Mt.Company.View.DepartmentView.edit_window.saveBtn.setText('修 改');
				Mt.Company.View.DepartmentView.edit_window.resetBtn.setVisible(true);
				Mt.Company.View.DepartmentView.edit_window.setTitle('修改部门');
				Mt.Company.View.DepartmentView.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
				Mt.Company.View.DepartmentView.edit_window.savetype=1;

				Mt.Company.View.DepartmentView.edit_window.show();
				Mt.Company.View.DepartmentView.edit_window.maximize();
			},
			/**
			 * 删除部门
			 */
			deleteDepartment : function() {
				Ext.Msg.confirm('提示', '确实要删除所选的部门吗?', this.confirmDeleteDepartment,this);
			},
			/**
			 * 确认删除部门
			 */
			confirmDeleteDepartment : function(btn) {
				if (btn == 'yes') {
					var del_department_ids ="";
					var selectedRows  = this.getSelectionModel().getSelections();
					for ( var flag = 0; flag < selectedRows.length; flag++) {
						del_department_ids=del_department_ids+selectedRows[flag].data.department_id+",";
					}
					ExtServiceDepartment.deleteByIds(del_department_ids);
					this.doSelectDepartment();
					Ext.Msg.alert("提示", "删除成功！");
				}
			}
		})
	},
	/**
	 * 视图：职位列表
	 */
	PositionView:{
		/**
		 *  当前创建的职位编辑窗口
		 */
		edit_window:null,
		/**
		 * 编辑窗口：新建或者修改职位
		 */
		EditWindow:Ext.extend(Ext.Window,{
			constructor : function(config) {
				config = Ext.apply({
					/**
					 * 自定义类型:保存类型
					 * 0:保存窗口,1:修改窗口
					 */
					savetype:0,closeAction : "hide",constrainHeader:true,maximizable: true,collapsible: true,
					width : 450,height : 550,minWidth : 400,minHeight : 450,
					layout : 'fit',plain : true,buttonAlign : 'center',
					defaults : {autoScroll : true},
					listeners:{
						beforehide:function(){
							this.editForm.form.getEl().dom.reset();
						}
					},
					items : [
						new Ext.form.FormPanel({
							ref:'editForm',layout:'form',
							labelWidth : 100,labelAlign : "center",
							bodyStyle : 'padding:5px 5px 0',align : "center",
							api : {},
							defaults : {
								xtype : 'textfield',anchor:'98%'
							},
							items : [
                {xtype: 'hidden',name : 'position_id',ref:'../position_id'},
                {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
                {xtype: 'hidden',name : 'department_id',ref:'../department_id'},
                {
                   fieldLabel : '部门',xtype: 'combo',name : 'department_name',ref : '../department_name',
                   store:Mt.Company.Store.departmentStoreForCombo,emptyText: '请选择部门',itemSelector: 'div.search-item',
                   loadingText: '查询中...',width: 570, pageSize:Mt.Company.Config.PageSize,
                   displayField:'department_name',grid:this,
                   mode: 'remote',  editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                   forceSelection: true,triggerAction: 'all',resizable:false,selectOnFocus:true,
                   tpl:new Ext.XTemplate(
                     '<tpl for="."><div class="search-item">',
                       '<h3>{department_name}</h3>',
                     '</div></tpl>'
                   ),
                   listeners:{
                     'beforequery': function(event){delete event.combo.lastQuery;}
                   },
                   onSelect:function(record,index){
                     if(this.fireEvent('beforeselect', this, record, index) !== false){
                      this.grid.department_id.setValue(record.data.department_id);
                      this.grid.department_name.setValue(record.data.department_name);
                      this.collapse();
                     }
                   }
                },
                {fieldLabel : '职位名称',name : 'position_name'}
							]
						})
					],
					buttons : [{
						text: "",ref : "../saveBtn",scope:this,
						handler : function() {

							if (!this.editForm.getForm().isValid()) {
								return;
							}
							editWindow=this;
							if (this.savetype==0){
								this.editForm.api.submit=ExtServicePosition.save;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.alert("提示", "保存成功！");
										Mt.Company.View.Running.positionGrid.doSelectPosition();
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}else{
								this.editForm.api.submit=ExtServicePosition.update;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
											Mt.Company.View.Running.positionGrid.bottomToolbar.doRefresh();
										}});
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}
						}
					}, {
						text : "取 消",scope:this,
						handler : function() {
							this.hide();
						}
					}, {
						text : "重 置",ref:'../resetBtn',scope:this,
						handler : function() {
							this.editForm.form.loadRecord(Mt.Company.View.Running.positionGrid.getSelectionModel().getSelected());

						}
					}]
				}, config);
				Mt.Company.View.PositionView.EditWindow.superclass.constructor.call(this, config);
			}
		}),
		/**
		 * 查询条件
		 */
		filter:null,
		/**
		 * 视图：职位列表
		 */
		Grid:Ext.extend(Ext.grid.GridPanel, {
			constructor : function(config) {
				config = Ext.apply({
					store : Mt.Company.Store.positionStore,sm : this.sm,
					frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
					loadMask : true,stripeRows : true,headerAsText : false,
					defaults : {autoScroll : true},
					cm : new Ext.grid.ColumnModel({
						defaults:{
							width:120,sortable : true
						},
						columns : [
              this.sm,
              {header : '标识',dataIndex : 'position_id',hidden:true},
              {header : '部门',dataIndex : 'department_name'},
              {header : '职位名称',dataIndex : 'position_name'}
						]
					}),
					tbar : {
						xtype : 'container',layout : 'anchor',
						height : 27,style:'font-size:14px',
						defaults : {
							height : 27,anchor : '100%'
						},
						items : [
							/*new Ext.Toolbar({
								defaults:{
								  scope: this
								},
								items : [
									{
										text: '反选',iconCls : 'icon-reverse',
										handler: function(){
											this.onReverseSelect();
										}
									},'-',{
										text : '添加职位',iconCls : 'icon-add',
										handler : function() {
											this.addPosition();
										}
									},'-',{
										text : '修改职位',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
										handler : function() {
											this.updatePosition();
										}
									},'-',{
										text : '删除职位', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
										handler : function() {
											this.deletePosition();
										}
									},'-']}
						)*/]
					},
					bbar: new Ext.PagingToolbar({
						pageSize: Mt.Company.Config.PageSize,
						store: Mt.Company.Store.positionStore,scope:this,autoShow:true,displayInfo: true,
						displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',emptyMsg: "无显示数据",
						items: [
							{xtype:'label', text: '每页显示'},
							{xtype:'numberfield', value:Mt.Company.Config.PageSize,minValue:1,width:35,style:'text-align:center',allowBlank: false,
								listeners:
								{
									change:function(Field, newValue, oldValue){
										var num = parseInt(newValue);
										if (isNaN(num) || !num || num<1)
										{
											num = Mt.Company.Config.PageSize;
											Field.setValue(num);
										}
										this.ownerCt.pageSize= num;
										Mt.Company.Config.PageSize = num;
										this.ownerCt.ownerCt.doSelectPosition();
									},
									specialKey :function(field,e){
										if (e.getKey() == Ext.EventObject.ENTER){
											var num = parseInt(field.getValue());
											if (isNaN(num) || !num || num<1)num = Mt.Company.Config.PageSize;
											this.ownerCt.pageSize= num;
											Mt.Company.Config.PageSize = num;
											this.ownerCt.ownerCt.doSelectPosition();
										}
									}
								}
							},{xtype:'label', text: '个'}
						]
					})
				}, config);
				/**
				 * 职位数据模型获取数据Direct调用
				 */
				Mt.Company.Store.positionStore.proxy=new Ext.data.DirectProxy({
					api: {read:ExtServicePosition.queryPagePosition}
				});
				Mt.Company.View.PositionView.Grid.superclass.constructor.call(this, config);
			},
			/**
			 * 行选择器
			 */
			sm : new Ext.grid.CheckboxSelectionModel({
				listeners : {
					selectionchange:function(sm) {
						// 判断删除和更新按钮是否可以激活
						this.grid.btnRemove.setDisabled(sm.getCount() < 1);
						this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
					}
				}
			}),
			/**
			 * 查询符合条件的职位
			 */
			doSelectPosition : function() {
				if (Mt.Company.View.Running.companyGrid&&Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected()){
					var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
					var condition = {'company_id':company_id,'start':0,'limit':Mt.Company.Config.PageSize};
					this.filter     ={'company_id':company_id};
					ExtServicePosition.queryPagePosition(condition,function(provider, response) {
						if (response.result){
							if (response.result.data) {
								var result       = new Array();
								result['data']     =response.result.data;
								result['totalCount'] =response.result.totalCount;
								Mt.Company.Store.positionStore.loadData(result);
							} else {
								Mt.Company.Store.positionStore.removeAll();
								Ext.Msg.alert('提示', '无符合条件的职位！');
							}

							if (Mt.Company.Store.positionStore.getTotalCount()>Mt.Company.Config.PageSize){
								 Mt.Company.View.Running.positionGrid.bottomToolbar.show();
							}else{
								 Mt.Company.View.Running.positionGrid.bottomToolbar.hide();
							}
							Mt.Company.View.Running.companyGrid.ownerCt.doLayout();
						}
					});
				}
			},
			/**
			 * 反选
			 */
			onReverseSelect:function() {
				for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
					if (this.sm.isSelected(i)) {
						this.sm.deselectRow(i);
					}else {
						this.sm.selectRow(i, true);
					}
				}
			},
			/**
			 * 新建职位
			 */
			addPosition : function(){
				if (Mt.Company.View.PositionView.edit_window==null){
					Mt.Company.View.PositionView.edit_window=new Mt.Company.View.PositionView.EditWindow();
				}
				Mt.Company.View.PositionView.edit_window.resetBtn.setVisible(false);
				Mt.Company.View.PositionView.edit_window.saveBtn.setText('保 存');
				Mt.Company.View.PositionView.edit_window.setTitle('添加职位');
				Mt.Company.View.PositionView.edit_window.savetype=0;
				Mt.Company.View.PositionView.edit_window.position_id.setValue("");
				var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
				Mt.Company.View.PositionView.edit_window.company_id.setValue(company_id);

				Mt.Company.View.PositionView.edit_window.show();
				Mt.Company.View.PositionView.edit_window.maximize();
			},
			/**
			 * 编辑职位时先获得选中的职位信息
			 */
			updatePosition : function() {
				if (Mt.Company.View.PositionView.edit_window==null){
					Mt.Company.View.PositionView.edit_window=new Mt.Company.View.PositionView.EditWindow();
				}
				Mt.Company.View.PositionView.edit_window.saveBtn.setText('修 改');
				Mt.Company.View.PositionView.edit_window.resetBtn.setVisible(true);
				Mt.Company.View.PositionView.edit_window.setTitle('修改职位');
				Mt.Company.View.PositionView.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
				Mt.Company.View.PositionView.edit_window.savetype=1;

				Mt.Company.View.PositionView.edit_window.show();
				Mt.Company.View.PositionView.edit_window.maximize();
			},
			/**
			 * 删除职位
			 */
			deletePosition : function() {
				Ext.Msg.confirm('提示', '确实要删除所选的职位吗?', this.confirmDeletePosition,this);
			},
			/**
			 * 确认删除职位
			 */
			confirmDeletePosition : function(btn) {
				if (btn == 'yes') {
					var del_position_ids ="";
					var selectedRows  = this.getSelectionModel().getSelections();
					for ( var flag = 0; flag < selectedRows.length; flag++) {
						del_position_ids=del_position_ids+selectedRows[flag].data.position_id+",";
					}
					ExtServicePosition.deleteByIds(del_position_ids);
					this.doSelectPosition();
					Ext.Msg.alert("提示", "删除成功！");
				}
			}
		})
	},
	/**
	 * 视图：企业课程列表
	 */
	LessonView:{
		/**
		 *  当前创建的企业课程编辑窗口
		 */
		edit_window:null,
		/**
		 * 编辑窗口：新建或者修改企业课程
		 */
		EditWindow:Ext.extend(Ext.Window,{
			constructor : function(config) {
				config = Ext.apply({
					/**
					 * 自定义类型:保存类型
					 * 0:保存窗口,1:修改窗口
					 */
					savetype:0,closeAction : "hide",constrainHeader:true,maximizable: true,collapsible: true,
					width : 450,height : 550,minWidth : 400,minHeight : 450,
					layout : 'fit',plain : true,buttonAlign : 'center',
					defaults : {autoScroll : true},
					listeners:{
						beforehide:function(){
							this.editForm.form.getEl().dom.reset();
						}
					},
					items : [
						new Ext.form.FormPanel({
							ref:'editForm',layout:'form',
							labelWidth : 100,labelAlign : "center",
							bodyStyle : 'padding:5px 5px 0',align : "center",
							api : {},
							defaults : {
								xtype : 'textfield',anchor:'98%'
							},
							items : [
                {xtype: 'hidden',name : 'lesson_id',ref:'../lesson_id'},
                {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
                {fieldLabel : '课程名称',name : 'lesson_name'},
                {fieldLabel : '内容关键字',name : 'keywords'},
                {fieldLabel : '开始时间',name : 'begin_time',xtype : 'datefield',format : "Y-m-d"},
                {fieldLabel : '结束时间',name : 'end_time',xtype : 'datefield',format : "Y-m-d"},
                {fieldLabel : '排序',name : 'sort_order',xtype : 'numberfield'}
							]
						})
					],
					buttons : [{
						text: "",ref : "../saveBtn",scope:this,
						handler : function() {

							if (!this.editForm.getForm().isValid()) {
								return;
							}
							editWindow=this;
							if (this.savetype==0){
								this.editForm.api.submit=ExtServiceLesson.save;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.alert("提示", "保存成功！");
										Mt.Company.View.Running.lessonGrid.doSelectLesson();
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}else{
								this.editForm.api.submit=ExtServiceLesson.update;
								this.editForm.getForm().submit({
									success : function(form, action) {
										Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
											Mt.Company.View.Running.lessonGrid.bottomToolbar.doRefresh();
										}});
										form.reset();
										editWindow.hide();
									},
									failure : function(form, response) {
										Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
									}
								});
							}
						}
					}, {
						text : "取 消",scope:this,
						handler : function() {
							this.hide();
						}
					}, {
						text : "重 置",ref:'../resetBtn',scope:this,
						handler : function() {
							this.editForm.form.loadRecord(Mt.Company.View.Running.lessonGrid.getSelectionModel().getSelected());

						}
					}]
				}, config);
				Mt.Company.View.LessonView.EditWindow.superclass.constructor.call(this, config);
			}
		}),
		/**
		 * 查询条件
		 */
		filter:null,
		/**
		 * 视图：企业课程列表
		 */
		Grid:Ext.extend(Ext.grid.GridPanel, {
			constructor : function(config) {
				config = Ext.apply({
					store : Mt.Company.Store.lessonStore,sm : this.sm,
					frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
					loadMask : true,stripeRows : true,headerAsText : false,
					defaults : {autoScroll : true},
					cm : new Ext.grid.ColumnModel({
						defaults:{
							width:120,sortable : true
						},
						columns : [
              this.sm,
              {header : '标识',dataIndex : 'lesson_id',hidden:true},
              {header : '课程名称',dataIndex : 'lesson_name'},
              {header : '内容关键字',dataIndex : 'keywords'},
              {header : '开始时间',dataIndex : 'begin_time',renderer:Ext.util.Format.dateRenderer('Y-m-d')},
              {header : '结束时间',dataIndex : 'end_time',renderer:Ext.util.Format.dateRenderer('Y-m-d')},
              {header : '排序',dataIndex : 'sort_order'}
						]
					}),
					tbar : {
						xtype : 'container',layout : 'anchor',
						height : 27,style:'font-size:14px',
						defaults : {
							height : 27,anchor : '100%'
						},
						items : [
							/*new Ext.Toolbar({
								defaults:{
								  scope: this
								},
								items : [
									{
										text: '反选',iconCls : 'icon-reverse',
										handler: function(){
											this.onReverseSelect();
										}
									},'-',{
										text : '添加企业课程',iconCls : 'icon-add',
										handler : function() {
											this.addLesson();
										}
									},'-',{
										text : '修改企业课程',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
										handler : function() {
											this.updateLesson();
										}
									},'-',{
										text : '删除企业课程', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
										handler : function() {
											this.deleteLesson();
										}
									},'-']}
						)*/]
					},
					bbar: new Ext.PagingToolbar({
						pageSize: Mt.Company.Config.PageSize,
						store: Mt.Company.Store.lessonStore,scope:this,autoShow:true,displayInfo: true,
						displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',emptyMsg: "无显示数据",
						items: [
							{xtype:'label', text: '每页显示'},
							{xtype:'numberfield', value:Mt.Company.Config.PageSize,minValue:1,width:35,style:'text-align:center',allowBlank: false,
								listeners:
								{
									change:function(Field, newValue, oldValue){
										var num = parseInt(newValue);
										if (isNaN(num) || !num || num<1)
										{
											num = Mt.Company.Config.PageSize;
											Field.setValue(num);
										}
										this.ownerCt.pageSize= num;
										Mt.Company.Config.PageSize = num;
										this.ownerCt.ownerCt.doSelectLesson();
									},
									specialKey :function(field,e){
										if (e.getKey() == Ext.EventObject.ENTER){
											var num = parseInt(field.getValue());
											if (isNaN(num) || !num || num<1)num = Mt.Company.Config.PageSize;
											this.ownerCt.pageSize= num;
											Mt.Company.Config.PageSize = num;
											this.ownerCt.ownerCt.doSelectLesson();
										}
									}
								}
							},{xtype:'label', text: '个'}
						]
					})
				}, config);
				/**
				 * 企业课程数据模型获取数据Direct调用
				 */
				Mt.Company.Store.lessonStore.proxy=new Ext.data.DirectProxy({
					api: {read:ExtServiceLesson.queryPageLesson}
				});
				Mt.Company.View.LessonView.Grid.superclass.constructor.call(this, config);
			},
			/**
			 * 行选择器
			 */
			sm : new Ext.grid.CheckboxSelectionModel({
				listeners : {
					selectionchange:function(sm) {
						// 判断删除和更新按钮是否可以激活
						this.grid.btnRemove.setDisabled(sm.getCount() < 1);
						this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
					}
				}
			}),
			/**
			 * 查询符合条件的企业课程
			 */
			doSelectLesson : function() {
				if (Mt.Company.View.Running.companyGrid&&Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected()){
					var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
					var condition = {'company_id':company_id,'start':0,'limit':Mt.Company.Config.PageSize};
					this.filter     ={'company_id':company_id};
					ExtServiceLesson.queryPageLesson(condition,function(provider, response) {
						if (response.result){
							if (response.result.data) {
								var result       = new Array();
								result['data']     =response.result.data;
								result['totalCount'] =response.result.totalCount;
								Mt.Company.Store.lessonStore.loadData(result);
							} else {
								Mt.Company.Store.lessonStore.removeAll();
								Ext.Msg.alert('提示', '无符合条件的企业课程！');
							}

							if (Mt.Company.Store.lessonStore.getTotalCount()>Mt.Company.Config.PageSize){
								 Mt.Company.View.Running.lessonGrid.bottomToolbar.show();
							}else{
								 Mt.Company.View.Running.lessonGrid.bottomToolbar.hide();
							}
							Mt.Company.View.Running.companyGrid.ownerCt.doLayout();
						}
					});
				}
			},
			/**
			 * 反选
			 */
			onReverseSelect:function() {
				for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
					if (this.sm.isSelected(i)) {
						this.sm.deselectRow(i);
					}else {
						this.sm.selectRow(i, true);
					}
				}
			},
			/**
			 * 新建企业课程
			 */
			addLesson : function(){
				if (Mt.Company.View.LessonView.edit_window==null){
					Mt.Company.View.LessonView.edit_window=new Mt.Company.View.LessonView.EditWindow();
				}
				Mt.Company.View.LessonView.edit_window.resetBtn.setVisible(false);
				Mt.Company.View.LessonView.edit_window.saveBtn.setText('保 存');
				Mt.Company.View.LessonView.edit_window.setTitle('添加企业课程');
				Mt.Company.View.LessonView.edit_window.savetype=0;
				Mt.Company.View.LessonView.edit_window.lesson_id.setValue("");
				var company_id = Mt.Company.View.Running.companyGrid.getSelectionModel().getSelected().data.company_id;
				Mt.Company.View.LessonView.edit_window.company_id.setValue(company_id);

				Mt.Company.View.LessonView.edit_window.show();
				Mt.Company.View.LessonView.edit_window.maximize();
			},
			/**
			 * 编辑企业课程时先获得选中的企业课程信息
			 */
			updateLesson : function() {
				if (Mt.Company.View.LessonView.edit_window==null){
					Mt.Company.View.LessonView.edit_window=new Mt.Company.View.LessonView.EditWindow();
				}
				Mt.Company.View.LessonView.edit_window.saveBtn.setText('修 改');
				Mt.Company.View.LessonView.edit_window.resetBtn.setVisible(true);
				Mt.Company.View.LessonView.edit_window.setTitle('修改企业课程');
				Mt.Company.View.LessonView.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
				Mt.Company.View.LessonView.edit_window.savetype=1;

				Mt.Company.View.LessonView.edit_window.show();
				Mt.Company.View.LessonView.edit_window.maximize();
			},
			/**
			 * 删除企业课程
			 */
			deleteLesson : function() {
				Ext.Msg.confirm('提示', '确实要删除所选的企业课程吗?', this.confirmDeleteLesson,this);
			},
			/**
			 * 确认删除企业课程
			 */
			confirmDeleteLesson : function(btn) {
				if (btn == 'yes') {
					var del_lesson_ids ="";
					var selectedRows  = this.getSelectionModel().getSelections();
					for ( var flag = 0; flag < selectedRows.length; flag++) {
						del_lesson_ids=del_lesson_ids+selectedRows[flag].data.lesson_id+",";
					}
					ExtServiceLesson.deleteByIds(del_lesson_ids);
					this.doSelectLesson();
					Ext.Msg.alert("提示", "删除成功！");
				}
			}
		})
	},
	/**
	 * 窗口：批量上传企业
	 */
	UploadWindow:Ext.extend(Ext.Window,{
		constructor : function(config) {
			config = Ext.apply({
				title : '批量上传企业数据',width : 400,height : 110,minWidth : 300,minHeight : 100,
				layout : 'fit',plain : true,bodyStyle : 'padding:5px;',buttonAlign : 'center',closeAction : "hide",
				items : [
					new Ext.form.FormPanel({
						ref:'uploadForm',fileUpload: true,
						width: 500,labelWidth: 50,autoHeight: true,baseCls: 'x-plain',
						frame:true,bodyStyle: 'padding: 10px 10px 10px 10px;',
						defaults: {
							anchor: '95%',allowBlank: false,msgTarget: 'side'
						},
						items : [{
							xtype : 'fileuploadfield',
							fieldLabel : '文 件',name : 'upload_file',ref:'upload_file',
							emptyText: '请上传企业Excel文件',buttonText: '',
							accept:'application/vnd.ms-excel',
							buttonCfg: {iconCls: 'upload-icon'}
						}]
					})
				],
				buttons : [{
						text : '上 传',
						scope:this,
						handler : function() {
							uploadWindow       =this;
							validationExpression   =/([\u4E00-\u9FA5]|\w)+(.xlsx|.XLSX|.xls|.XLS)$/;/**允许中文名*/
							var isValidExcelFormat = new RegExp(validationExpression);
							var result       = isValidExcelFormat.test(this.uploadForm.upload_file.getValue());
							if (!result){
								Ext.Msg.alert('提示', '请上传Excel文件，后缀名为xls或者xlsx！');
								return;
							}
							if (this.uploadForm.getForm().isValid()) {
								Ext.Msg.show({
									title : '请等待',msg : '文件正在上传中，请稍后...',
									animEl : 'loading',icon : Ext.Msg.WARNING,
									closable : true,progress : true,progressText : '',width : 300
								});
								this.uploadForm.getForm().submit({
									url : 'index.php?go=admin.upload.uploadCompany',
									success : function(form, response) {
										Ext.Msg.alert('成功', '上传成功');
										uploadWindow.hide();
										uploadWindow.uploadForm.upload_file.setValue('');
										Mt.Company.View.Running.companyGrid.doSelectCompany();
									},
									failure : function(form, response) {
										Ext.Msg.alert('错误', response.result.data);
									}
								});
							}
						}
					},{
						text : '取 消',
						scope:this,
						handler : function() {
							this.uploadForm.upload_file.setValue('');
							this.hide();
						}
					}]
				}, config);
			Mt.Company.View.UploadWindow.superclass.constructor.call(this, config);
		}
	}),
	/**
	 * 窗口：批量上传商品图片
	 */
	BatchUploadImagesWindow:Ext.extend(Ext.Window,{
		constructor : function(config) {
			config = Ext.apply({
				width : 400,height : 180,minWidth : 300,minHeight : 100,closeAction : "hide",
				layout : 'fit',plain : true,bodyStYle : 'padding:5px;',buttonAlign : 'center',
				items : [
					new Ext.form.FormPanel({
						ref:'uploadForm',fileUpload: true,
						width: 500,labelWidth: 50,autoHeight: true,baseCls: 'x-plain',
						frame:true,bodyStyle: 'padding: 10px 10px 10px 10px;',
						defaults: {
							anchor: '95%',allowBlank: false,msgTarget: 'side'
						},
						items : [{
							xtype : 'fileuploadfield',fieldLabel : '文 件',ref:'upload_file',
							emptyText: '请批量上传更新时间文件(zip)',buttonText: '',
							accept:'application/zip,application/x-zip-compressed',
							buttonCfg: {iconCls: 'upload-icon'}
						},
						{xtype : 'displayfield',value:'*.图片名不能重名<br/>*.压缩文件最大不要超过50M'}]
					})
				],
				buttons : [{
						text : '上 传',
						scope:this,
						handler : function() {
							uploadImagesWindow   =this;
							validationExpression   =/([\u4E00-\u9FA5]|\w)+(.zip|.ZIP)$/;
							var isValidExcelFormat = new RegExp(validationExpression);
							var result       = isValidExcelFormat.test(this.uploadForm.upload_file.getValue());
							if (!result){
								Ext.Msg.alert('提示', '请上传ZIP文件，后缀名为zip！');
								return;
							}
							var uploadImageUrl='index.php?go=admin.upload.uploadCompanyLogo_images';

							if (this.uploadForm.getForm().isValid()) {
								Ext.Msg.show({
									title : '请等待',msg : '文件正在上传中，请稍后...',
									animEl : 'loading',icon : Ext.Msg.WARNING,
									closable : true,progress : true,progressText : '',width : 300
								});
								this.uploadForm.getForm().submit({
									url : uploadImageUrl,
									success : function(form, response) {
										Ext.Msg.alert('成功', '上传成功');
										uploadImagesWindow.hide();
										uploadImagesWindow.uploadForm.upload_file.setValue('');
										Mt.Company.View.Running.companyGrid.doSelectCompany();
									},
									failure : function(form, response) {
										if (response.result&&response.result.data){
											Ext.Msg.alert('错误', response.result.data);
										}
									}
								});
							}
						}
					},{
						text : '取 消',
						scope:this,
						handler : function() {
							this.uploadForm.upload_file.setValue('');
							this.hide();
						}
					}]
				}, config);
			Mt.Company.View.BatchUploadImagesWindow.superclass.constructor.call(this, config);
		}
	}),
	/**
	 * 视图：企业列表
	 */
	Grid:Ext.extend(Ext.grid.GridPanel, {
		constructor : function(config) {
			config = Ext.apply({
				/**
				 * 查询条件
				 */
				filter:null,
				region : 'center',
				store : Mt.Company.Store.companyStore,
				sm : this.sm,
				frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
				loadMask : true,stripeRows : true,headerAsText : false,
				defaults : {
					autoScroll : true
				},
				cm : new Ext.grid.ColumnModel({
					defaults:{
						width:120,sortable : true
					},
					columns : [
						this.sm,
            {header : '标识',dataIndex : 'company_id',hidden:true},
            {header : '企业名称',dataIndex : 'company_name'},
            {header : '地址',dataIndex : 'address'},
            {header : '电话',dataIndex : 'tel'},
            {header : '开始时间',dataIndex : 'begin_time',renderer:Ext.util.Format.dateRenderer('Y-m-d')},
            {header : '结束时间',dataIndex : 'end_time',renderer:Ext.util.Format.dateRenderer('Y-m-d')}
					]
				}),
				tbar : {
					xtype : 'container',layout : 'anchor',height : 27 * 2,style:'font-size:14px',
					defaults : {
						height : 27,anchor : '100%'
					},
					items : [
						new Ext.Toolbar({
							enableOverflow: true,width : 100,
							defaults : {
								xtype : 'textfield',
								listeners : {
								   specialkey : function(field, e) {
										if (e.getKey() == Ext.EventObject.ENTER)this.ownerCt.ownerCt.ownerCt.doSelectCompany();
									}
								}
							},
							items : [
                '企业名称','&nbsp;&nbsp;',{ref: '../ccompany_name'},'&nbsp;&nbsp;',
								{
									xtype : 'button',text : '查询',scope: this,
									handler : function() {
										this.doSelectCompany();
									}
								},
								{
									xtype : 'button',text : '重置',scope: this,
									handler : function() {
                    this.topToolbar.ccompany_name.setValue("");
										this.filter={};
										this.doSelectCompany();
									}
								}]
						}),
						new Ext.Toolbar({
							defaults:{scope: this},
							items : [
								{
									text: '反选',iconCls : 'icon-reverse',
									handler: function(){
										this.onReverseSelect();
									}
								},'-',{
									text : '添加企业',iconCls : 'icon-add',
									handler : function() {
										this.addCompany();
									}
								},'-',{
									text : '修改企业',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
									handler : function() {
										this.updateCompany();
									}
								},'-',{
									text : '删除企业', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
									handler : function() {
										this.deleteCompany();
									}
								},'-',{
									xtype:'tbsplit',text: '导入', iconCls : 'icon-import',
									handler : function() {
										this.importCompany();
									},
									menu: {
										xtype:'menu',plain:true,
										items: [
											{text:'批量导入企业',iconCls : 'icon-import',scope:this,handler:function(){this.importCompany()}},
                      {text:'批量导入logo图片',iconCls : 'icon-import',scope:this,handler:function(){this.batchUploadImages("upload_logo_image_files","logo图片")}}
										]}
								},'-',{
									text : '导出',iconCls : 'icon-export',
									handler : function() {
										this.exportCompany();
									}
								},'-',{
									xtype:'tbsplit',text: '查看企业', ref:'../../tvpView',iconCls : 'icon-updown',
									enableToggle: true, disabled : true,
									handler:function(){this.showCompany()},
									menu: {
										xtype:'menu',plain:true,
										items: [
											{text:'上方',group:'mlayout',checked:false,iconCls:'view-top',scope:this,handler:function(){this.onUpDown(1)}},
											{text:'下方',group:'mlayout',checked:true ,iconCls:'view-bottom',scope:this,handler:function(){this.onUpDown(2)}},
											{text:'左侧',group:'mlayout',checked:false,iconCls:'view-left',scope:this,handler:function(){this.onUpDown(3)}},
											{text:'右侧',group:'mlayout',checked:false,iconCls:'view-right',scope:this,handler:function(){this.onUpDown(4)}},
											{text:'隐藏',group:'mlayout',checked:false,iconCls:'view-hide',scope:this,handler:function(){this.hideCompany();Mt.Company.Config.View.IsShow=0;}},'-',
											{text: '固定',ref:'mBind',checked: true,scope:this,checkHandler:function(item, checked){this.onBindGrid(item, checked);Mt.Company.Cookie.set('View.IsFix',Mt.Company.Config.View.IsFix);}}
										]}
								},'-']}
					)]
				},
				bbar: new Ext.PagingToolbar({
					pageSize: Mt.Company.Config.PageSize,
					store: Mt.Company.Store.companyStore,
					scope:this,autoShow:true,displayInfo: true,
					displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',
					emptyMsg: "无显示数据",
					listeners:{
						change:function(thisbar,pagedata){
							if (Mt.Company.Viewport){
								if (Mt.Company.Config.View.IsShow==1){
									Mt.Company.View.IsSelectView=1;
								}
								this.ownerCt.hideCompany();
								Mt.Company.Config.View.IsShow=0;
							}
						}
					},
					items: [
						{xtype:'label', text: '每页显示'},
						{xtype:'numberfield', value:Mt.Company.Config.PageSize,minValue:1,width:35,
							style:'text-align:center',allowBlank: false,
							listeners:
							{
								change:function(Field, newValue, oldValue){
									var num = parseInt(newValue);
									if (isNaN(num) || !num || num<1)
									{
										num = Mt.Company.Config.PageSize;
										Field.setValue(num);
									}
									this.ownerCt.pageSize= num;
									Mt.Company.Config.PageSize = num;
									this.ownerCt.ownerCt.doSelectCompany();
								},
								specialKey :function(field,e){
									if (e.getKey() == Ext.EventObject.ENTER){
										var num = parseInt(field.getValue());
										if (isNaN(num) || !num || num<1)
										{
											num = Mt.Company.Config.PageSize;
										}
										this.ownerCt.pageSize= num;
										Mt.Company.Config.PageSize = num;
										this.ownerCt.ownerCt.doSelectCompany();
									}
								}
							}
						},
						{xtype:'label', text: '个'}
					]
				})
			}, config);
			//初始化显示企业列表
			this.doSelectCompany();
			Mt.Company.View.Grid.superclass.constructor.call(this, config);
			//创建在Grid里显示的企业信息Tab页
			Mt.Company.View.Running.viewTabs=new Mt.Company.View.CompanyView.Tabs();
			this.addListener('rowdblclick', this.onRowDoubleClick);
		},
		/**
		 * 行选择器
		 */
		sm : new Ext.grid.CheckboxSelectionModel({
			//handleMouseDown : Ext.emptyFn,
			listeners : {
				selectionchange:function(sm) {
					// 判断删除和更新按钮是否可以激活
					this.grid.btnRemove.setDisabled(sm.getCount() < 1);
					this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
					this.grid.tvpView.setDisabled(sm.getCount() != 1);
				},
				rowselect: function(sm, rowIndex, record) {
					if (sm.getCount() != 1){
						this.grid.hideCompany();
						Mt.Company.Config.View.IsShow=0;
					}else{
						if (Mt.Company.View.IsSelectView==1){
							Mt.Company.View.IsSelectView=0;
							this.grid.showCompany();
						}
					}
				},
				rowdeselect: function(sm, rowIndex, record) {
					if (sm.getCount() != 1){
						if (Mt.Company.Config.View.IsShow==1){
							Mt.Company.View.IsSelectView=1;
						}
						this.grid.hideCompany();
						Mt.Company.Config.View.IsShow=0;
					}
				}
			}
		}),
		/**
		 * 双击选行
		 */
		onRowDoubleClick:function(grid, rowIndex, e){
			if (!Mt.Company.Config.View.IsShow){
				this.sm.selectRow(rowIndex);
				this.showCompany();
				this.tvpView.toggle(true);
			}else{
				this.hideCompany();
				Mt.Company.Config.View.IsShow=0;
				this.sm.deselectRow(rowIndex);
				this.tvpView.toggle(false);
			}
		},
		/**
		 * 是否绑定在本窗口上
		 */
		onBindGrid:function(item, checked){
			if (checked){
			   Mt.Company.Config.View.IsFix=1;
			}else{
			   Mt.Company.Config.View.IsFix=0;
			}
			if (this.getSelectionModel().getSelected()==null){
				Mt.Company.Config.View.IsShow=0;
				return ;
			}
			if (Mt.Company.Config.View.IsShow==1){
			   this.hideCompany();
			   Mt.Company.Config.View.IsShow=0;
			}
			this.showCompany();
		},
		/**
		 * 反选
		 */
		onReverseSelect:function() {
			for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
				if (this.sm.isSelected(i)) {
					this.sm.deselectRow(i);
				}else {
					this.sm.selectRow(i, true);
				}
			}
		},
		/**
		 * 查询符合条件的企业
		 */
		doSelectCompany : function() {
			if (this.topToolbar){
        var ccompany_name = this.topToolbar.ccompany_name.getValue();
        this.filter     ={'company_name':ccompany_name};
			}
			var condition = {'start':0,'limit':Mt.Company.Config.PageSize};
			Ext.apply(condition,this.filter);
			ExtServiceCompany.queryPageCompany(condition,function(provider, response) {
				if (response.result&&response.result.data) {
					var result       = new Array();
					result['data']     =response.result.data;
					result['totalCount'] =response.result.totalCount;
					Mt.Company.Store.companyStore.loadData(result);
				} else {
					Mt.Company.Store.companyStore.removeAll();
					Ext.Msg.alert('提示', '无符合条件的企业！');
				}
			});
		},
		/**
		 * 显示企业视图
		 * 显示企业的视图相对企业列表Grid的位置
		 * 1:上方,2:下方,0:隐藏。
		 */
		onUpDown:function(viewDirection){
			Mt.Company.Config.View.Direction=viewDirection;
			switch(viewDirection){
				case 1:
					this.ownerCt.north.add(Mt.Company.View.Running.viewTabs);
					break;
				case 2:
					this.ownerCt.south.add(Mt.Company.View.Running.viewTabs);
					break;
				case 3:
					this.ownerCt.west.add(Mt.Company.View.Running.viewTabs);
					break;
				case 4:
					this.ownerCt.east.add(Mt.Company.View.Running.viewTabs);
					break;
			}
			Mt.Company.Cookie.set('View.Direction',Mt.Company.Config.View.Direction);
			if (this.getSelectionModel().getSelected()!=null){
				if ((Mt.Company.Config.View.IsFix==0)&&(Mt.Company.Config.View.IsShow==1)){
					this.showCompany();
				}
				Mt.Company.Config.View.IsFix=1;
				Mt.Company.View.Running.companyGrid.tvpView.menu.mBind.setChecked(true,true);
				Mt.Company.Config.View.IsShow=0;
				this.showCompany();
			}
		},
		/**
		 * 显示企业
		 */
		showCompany : function(){
			if (this.getSelectionModel().getSelected()==null){
				Ext.Msg.alert('提示', '请先选择企业！');
				Mt.Company.Config.View.IsShow=0;
				this.tvpView.toggle(false);
				return ;
			}
			if (Mt.Company.Config.View.IsFix==0){
				if (Mt.Company.View.Running.view_window==null){
					Mt.Company.View.Running.view_window=new Mt.Company.View.CompanyView.Window();
				}
				if (Mt.Company.View.Running.view_window.hidden){
					Mt.Company.View.Running.view_window.show();
					Mt.Company.View.Running.view_window.winTabs.hideTabStripItem(Mt.Company.View.Running.view_window.winTabs.tabFix);
					this.updateViewCompany();
					this.tvpView.toggle(true);
					Mt.Company.Config.View.IsShow=1;
				}else{
					this.hideCompany();
					Mt.Company.Config.View.IsShow=0;
				}
				return;
			}
			switch(Mt.Company.Config.View.Direction){
				case 1:
					if (!this.ownerCt.north.items.contains(Mt.Company.View.Running.viewTabs)){
						this.ownerCt.north.add(Mt.Company.View.Running.viewTabs);
					}
					break;
				case 2:
					if (!this.ownerCt.south.items.contains(Mt.Company.View.Running.viewTabs)){
						this.ownerCt.south.add(Mt.Company.View.Running.viewTabs);
					}
					break;
				case 3:
					if (!this.ownerCt.west.items.contains(Mt.Company.View.Running.viewTabs)){
						this.ownerCt.west.add(Mt.Company.View.Running.viewTabs);
					}
					break;
				case 4:
					if (!this.ownerCt.east.items.contains(Mt.Company.View.Running.viewTabs)){
						this.ownerCt.east.add(Mt.Company.View.Running.viewTabs);
					}
					break;
			}
			this.hideCompany();
			if (Mt.Company.Config.View.IsShow==0){
				Mt.Company.View.Running.viewTabs.enableCollapse();
				switch(Mt.Company.Config.View.Direction){
					case 1:
						this.ownerCt.north.show();
						break;
					case 2:
						this.ownerCt.south.show();
						break;
					case 3:
						this.ownerCt.west.show();
						break;
					case 4:
						this.ownerCt.east.show();
						break;
				}
				this.updateViewCompany();
				this.tvpView.toggle(true);
				Mt.Company.Config.View.IsShow=1;
			}else{
				Mt.Company.Config.View.IsShow=0;
			}
			this.ownerCt.doLayout();
		},
		/**
		 * 隐藏企业
		 */
		hideCompany : function(){
			this.ownerCt.north.hide();
			this.ownerCt.south.hide();
			this.ownerCt.west.hide();
			this.ownerCt.east.hide();
			if (Mt.Company.View.Running.view_window!=null){
				Mt.Company.View.Running.view_window.hide();
			}
			this.tvpView.toggle(false);
			this.ownerCt.doLayout();
		},
		/**
		 * 更新当前企业显示信息
		 */
		updateViewCompany : function() {
      Mt.Company.View.Running.areaGrid.doSelectArea();
      Mt.Company.View.Running.departmentGrid.doSelectDepartment();
      Mt.Company.View.Running.positionGrid.doSelectPosition();
      Mt.Company.View.Running.lessonGrid.doSelectLesson();
			if (Mt.Company.View.Running.view_window!=null){
				Mt.Company.View.Running.view_window.winTabs.tabCompanyDetail.update(this.getSelectionModel().getSelected().data);
			}
			Mt.Company.View.Running.viewTabs.tabCompanyDetail.update(this.getSelectionModel().getSelected().data);
		},
		/**
		 * 新建企业
		 */
		addCompany : function() {
			if (Mt.Company.View.Running.edit_window==null){
				Mt.Company.View.Running.edit_window=new Mt.Company.View.EditWindow();
			}
			Mt.Company.View.Running.edit_window.resetBtn.setVisible(false);
			Mt.Company.View.Running.edit_window.saveBtn.setText('保 存');
			Mt.Company.View.Running.edit_window.setTitle('添加企业');
			Mt.Company.View.Running.edit_window.savetype=0;
			Mt.Company.View.Running.edit_window.company_id.setValue("");
      		Mt.Company.View.Running.edit_window.logo_imageUpload.setValue("");
      		Mt.Company.View.Running.edit_window.links_imgUpload.setValue("");
			Mt.Company.View.Running.edit_window.show();
			Mt.Company.View.Running.edit_window.maximize();
		},
		/**
		 * 编辑企业时先获得选中的企业信息
		 */
		updateCompany : function() {
			if (Mt.Company.View.Running.edit_window==null){
				Mt.Company.View.Running.edit_window=new Mt.Company.View.EditWindow();
			}
			Mt.Company.View.Running.edit_window.saveBtn.setText('修 改');
			Mt.Company.View.Running.edit_window.resetBtn.setVisible(true);
			Mt.Company.View.Running.edit_window.setTitle('修改企业');
			Mt.Company.View.Running.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
			Mt.Company.View.Running.edit_window.savetype=1;
      		Mt.Company.View.Running.edit_window.logo_imageUpload.setValue(Mt.Company.View.Running.edit_window.logo_image.getValue());
      		Mt.Company.View.Running.edit_window.links_imgUpload.setValue(Mt.Company.View.Running.edit_window.links_img.getValue());
			Mt.Company.View.Running.edit_window.show();
			Mt.Company.View.Running.edit_window.maximize();
		},
		/**
		 * 删除企业
		 */
		deleteCompany : function() {
			Ext.Msg.confirm('提示', '确实要删除所选的企业吗?', this.confirmDeleteCompany,this);
		},
		/**
		 * 确认删除企业
		 */
		confirmDeleteCompany : function(btn) {
			if (btn == 'yes') {
				var del_company_ids ="";
				var selectedRows  = this.getSelectionModel().getSelections();
				for ( var flag = 0; flag < selectedRows.length; flag++) {
					del_company_ids=del_company_ids+selectedRows[flag].data.company_id+",";
				}
				ExtServiceCompany.deleteByIds(del_company_ids);
				this.doSelectCompany();
				Ext.Msg.alert("提示", "删除成功！");
			}
		},
		/**
		 * 导出企业
		 */
		exportCompany : function() {
			ExtServiceCompany.exportCompany(this.filter,function(provider, response) {
				if (response.result.data) {
					window.open(response.result.data);
				}
			});
		},
		/**
		 * 导入企业
		 */
		importCompany : function() {
			if (Mt.Company.View.current_uploadWindow==null){
				Mt.Company.View.current_uploadWindow=new Mt.Company.View.UploadWindow();
			}
			Mt.Company.View.current_uploadWindow.show();
		},
		/**
		 * 批量上传商品图片
		 */
		batchUploadImages:function(inputname,title){
			if (Mt.Company.View.Running.batchUploadImagesWindow==null){
        Mt.Company.View.Running.batchUploadImagesWindow=new Mt.Company.View.BatchUploadImagesWindow();
      }

			Mt.Company.View.Running.batchUploadImagesWindow.setTitle("批量上传"+title);
			Mt.Company.View.Running.batchUploadImagesWindow.uploadForm.upload_file.name=inputname;
			Mt.Company.View.Running.batchUploadImagesWindow.show();
		}
	}),
	/**
	 * 核心内容区
	 */
	Panel:Ext.extend(Ext.form.FormPanel,{
		constructor : function(config) {
			Mt.Company.View.Running.companyGrid=new Mt.Company.View.Grid();
			if (Mt.Company.Config.View.IsFix==0){
				Mt.Company.View.Running.companyGrid.tvpView.menu.mBind.setChecked(false,true);
			}
			config = Ext.apply({
				region : 'center',layout : 'fit', frame:true,
				items: {
					layout:'border',
					items:[
						Mt.Company.View.Running.companyGrid,
						{region:'north',ref:'north',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true},
						{region:'south',ref:'south',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true,items:[Mt.Company.View.Running.viewTabs]},
						{region:'west',ref:'west',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true},
						{region:'east',ref:'east',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true}
					]
				}
			}, config);
			Mt.Company.View.Panel.superclass.constructor.call(this, config);
		}
	}),
	/**
	 * 当前运行的可视化对象
	 */
	Running:{
		/**
		 * 当前企业Grid对象
		 */
		companyGrid:null,
    /**
     * 当前地区Grid对象
     */
    areaGrid:null,
    /**
     * 当前部门Grid对象
     */
    departmentGrid:null,
    /**
     * 当前职位Grid对象
     */
    positionGrid:null,
    /**
     * 当前企业课程Grid对象
     */
    lessonGrid:null,
		/**
		 * 显示企业信息及关联信息列表的Tab页
		 */
		viewTabs:null,
		/**
		 * 当前创建的编辑窗口
		 */
		edit_window:null,
		/**
		 * 当前的显示窗口
		 */
		view_window:null
	}
};
/**
 * Controller:主程序
 */
Ext.onReady(function(){
	Ext.QuickTips.init();
	Ext.state.Manager.setProvider(Mt.Company.Cookie);
	Ext.Direct.addProvider(Ext.app.REMOTING_API);
	Mt.Company.Init();
	/**
	 * 企业数据模型获取数据Direct调用
	 */
	Mt.Company.Store.companyStore.proxy=new Ext.data.DirectProxy({
		api: {read:ExtServiceCompany.queryPageCompany}
	});
	/**
	 * 企业页面布局
	 */
	Mt.Company.Viewport = new Ext.Viewport({
		layout : 'border',
		items : [new Mt.Company.View.Panel()]
	});
	Mt.Company.Viewport.doLayout();
	setTimeout(function(){
		Ext.get('loading').remove();
		Ext.get('loading-mask').fadeOut({
			remove:true
		});
	}, 250);
});